import 'package:get/get.dart';
import 'package:mtf/app/base/BaseController.dart';
import 'package:mtf/app/data/BankEntity.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:mtf/app/routes/app_pages.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class bankManagerController extends BaseController {
  RxList<ListBankElement> bankList = <ListBankElement>[].obs;

  void clickAddBank() async {
    await Get.toNamed(Routes.BANK_ADD);
    reqBankList();
  }

  void reqBankList() async {
    showLoading();
    var resp = await HttpManager.reqBankList();
    if (resp.isSuccessData()) {
      bankList.assignAll(resp.data!.list);
    }
    hideLoading();
  }

  void reqClickChoice(ListBankElement bean) {
    var isChoice = Get.arguments["choice"];
    if (isChoice != null && isChoice) {
      Get.back(result: {"bankNum": bean.bankAccount,"bankName":bean.bankName,"bId":bean.id.toString()});
    }
  }

  @override
  void onInit() {
    super.onInit();
    reqBankList();
  }

  void reqBankDelete(ListBankElement bean) async {
    showLoading();
    var resp = await HttpManager.reqBankDelete(bean.id.toString());
    if (resp.isSuccess()) {
      reqBankList();
    }
    hideLoading();
  }
}
